package com.kingwang.training.designpattern.observer.bo.jdk.propertychange;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.ToString;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

@ToString
@EqualsAndHashCode
public class Task {
    @Getter
    private String title;

    @Getter
    private String content;

    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);

    public void setTitle(String title) {
        String oldValue = this.title;
        this.title = title;
        this.changeSupport.firePropertyChange("title", oldValue, title);
    }

    public void setContent(String content) {
        String oldValue = this.content;
        this.content = content;
        this.changeSupport.firePropertyChange("content", oldValue, content);
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        this.changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        this.changeSupport.removePropertyChangeListener(listener);
    }
}
